package Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import java.io.IOException;

import javax.swing.JOptionPane;

import Entity.Customer;
import Entity.Order;
import Entity.Sale;
import GUI.MarketingEmployee.MarketingEmployeeGUI;
import GUI.SalesEmployee.SalesEmployeeGUI;
import Message.Message;
import S2.client.S2Client;


public class SalesEmpControler implements java.awt.event.ActionListener{
	
	private static final ActionListener SaleEmpControler = null;
	private SalesEmployeeGUI SEGui;
	private static GUI.SalesEmployee.SetOrderPnl setOrderPnl;
	static  S2Client clientConection;
	
	public SalesEmpControler(){
		if(clientConection == null)
		clientConection = MainControler.getInstance();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		
		//Switch by the relevant panel.
		
		switch (e.getActionCommand()) {
		
		case "Set Order":
			String sOrder;
			String sOCusId;
			String sOEmpId;
			String sODate;
			String sPrice;
			
			sOrder = SEGui.setOrderPnl.textFieldOrderId.getText();
			sOEmpId = SEGui.setOrderPnl.textFieldEmpId.getText();
			sOCusId =SEGui.setOrderPnl.textFieldCustomerId.getText();
			sODate = SEGui.setOrderPnl.textFieldDate.getText();
			sPrice = SEGui.setOrderPnl.textFieldPrice.getText();
			
		    Order addOrder = new Order(sOrder,sOEmpId,sOCusId,sODate,sPrice);
			Message addOrdermsg = new Message(addOrder,"Set Order");
			try {
				clientConection.sendToServer(addOrdermsg);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			
			SEGui.setOrderPnl.textFieldEmpId.setText("");
			SEGui.setOrderPnl.textFieldCustomerId.setText("");
			SEGui.setOrderPnl.textFieldDate.setText("");
			SEGui.setOrderPnl.textFieldOrderId.setText("");
			SEGui.setOrderPnl.textFieldPrice.setText("");
			
			
			break;
		case "cd":
			
			break;
			
		case "vd":
			
		break;
		
		case " ":
			
			break;
			

		default:
			System.out.println("btata");
			break;
		}
		
		
	}

	public void setView(SalesEmployeeGUI SEGui) {
		this.SEGui = SEGui;
	}

	public static void setNewOrderMsg(Message msg) {
		if((boolean)msg.getObj() == true)
			JOptionPane.showMessageDialog(null, "Added Successfully", "InfoBox: " + "SetNewOrder", JOptionPane.INFORMATION_MESSAGE);
		else 
			JOptionPane.showMessageDialog(null, "Added Faild!", "InfoBox: " + "SetNewOrder", JOptionPane.INFORMATION_MESSAGE);
		
	}
}
